package com.ruoyi.print.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.print.domain.SinglePhoto;
import com.ruoyi.print.service.ISinglePhotoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单个图片任务Controller
 * 
 * @author ruoyi
 * @date 2025-08-03
 */
@RestController
@RequestMapping("/print/photo")
public class SinglePhotoController extends BaseController
{
    @Autowired
    private ISinglePhotoService singlePhotoService;

    /**
     * 查询单个图片任务列表
     */
    @PreAuthorize("@ss.hasPermi('print:photo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SinglePhoto singlePhoto)
    {
        startPage();
        List<SinglePhoto> list = singlePhotoService.selectSinglePhotoList(singlePhoto);
        return getDataTable(list);
    }

    /**
     * 导出单个图片任务列表
     */
    @PreAuthorize("@ss.hasPermi('print:photo:export')")
    @Log(title = "单个图片任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SinglePhoto singlePhoto)
    {
        List<SinglePhoto> list = singlePhotoService.selectSinglePhotoList(singlePhoto);
        ExcelUtil<SinglePhoto> util = new ExcelUtil<SinglePhoto>(SinglePhoto.class);
        util.exportExcel(response, list, "单个图片任务数据");
    }

    /**
     * 获取单个图片任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('print:photo:query')")
    @GetMapping(value = "/{singlePhotoId}")
    public AjaxResult getInfo(@PathVariable("singlePhotoId") Long singlePhotoId)
    {
        return success(singlePhotoService.selectSinglePhotoBySinglePhotoId(singlePhotoId));
    }

    /**
     * 新增单个图片任务
     */
    @PreAuthorize("@ss.hasPermi('print:photo:add')")
    @Log(title = "单个图片任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SinglePhoto singlePhoto)
    {
        return toAjax(singlePhotoService.insertSinglePhoto(singlePhoto));
    }

    /**
     * 修改单个图片任务
     */
    @PreAuthorize("@ss.hasPermi('print:photo:edit')")
    @Log(title = "单个图片任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SinglePhoto singlePhoto)
    {
        return toAjax(singlePhotoService.updateSinglePhoto(singlePhoto));
    }

    /**
     * 删除单个图片任务
     */
    @PreAuthorize("@ss.hasPermi('print:photo:remove')")
    @Log(title = "单个图片任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{singlePhotoIds}")
    public AjaxResult remove(@PathVariable Long[] singlePhotoIds)
    {
        return toAjax(singlePhotoService.deleteSinglePhotoBySinglePhotoIds(singlePhotoIds));
    }

    /**
     * 根据任务ID查询照片列表
     */
    @PreAuthorize("@ss.hasPermi('print:photo:list')")
    @GetMapping("/task/{photoTaskId}")
    public TableDataInfo listByTaskId(@PathVariable("photoTaskId") Long photoTaskId)
    {
        startPage();
        List<SinglePhoto> list = singlePhotoService.selectSinglePhotosByPhotoTaskId(photoTaskId);
        return getDataTable(list);
    }

    /**
     * 批量删除照片
     */
    @PreAuthorize("@ss.hasPermi('print:photo:remove')")
    @Log(title = "单个图片任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/batch/{singlePhotoIds}")
    public AjaxResult removeBatch(@PathVariable Long[] singlePhotoIds)
    {
        return toAjax(singlePhotoService.deleteSinglePhotosBatch(singlePhotoIds));
    }
}
